package com.igd.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.context.support.ClassPathXmlApplicationContext;

 /**
 * @version  1.0
 *
 * @author   QIAOYU
 *
 * @date     2013-6-17
 *
 * @description	 Spring基础工具类
 */

public class SpringUtil extends ApplicationObjectSupport{

	/**
	 * 私有化构造函数,避免自主声明
	 */
	private SpringUtil(){};
	
	private static SpringUtil springUtil = null;
	
	/**
	 * 初始化函数,返回SpringUtil对象
	 * 
	 * @return
	 */
	public static SpringUtil getInstance(){
		
		if(null == springUtil){
			
			synchronized (SpringUtil.class) {
				
				springUtil = new SpringUtil();

			}
		}
		
		return springUtil;
	}
	
	/**
	 * 获取Bean值
	 * 
	 * @param beanName bean名称
	 * 
	 * @return
	 */
	public Object getBean(String beanName){

		return this.getApplicationContext().getBean(beanName);

	}
	
	/**
	 * 根据BeanName获得是否有此Bean对象
	 * 
	 * @param beanName
	 * 
	 * @return
	 */
	public boolean hasBean(String beanName){
		
		return this.getApplicationContext().containsBean(beanName);

	}
	
	/**
	 * 根据classpath文件系统获取ApplicationContext
	 * 
	 * @param fileName
	 * 
	 * @return
	 */
	public ApplicationContext getApplicationContextByFile(String fileName){
		
		return new ClassPathXmlApplicationContext(fileName);

	}
}
